package mlta.activities;


import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.content.Intent;

public class LoginActivity extends Activity {
	
	protected EditText edt_User,edt_Password;
	
	protected Button bt_Entrar;
	
	protected Button bt_Cadastrar;
	
	protected Button btn_help;
    
    protected Button btn_exit;
    
    	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.login);
        
        
        edt_User = (EditText) findViewById(R.id.edUser);
        edt_Password = (EditText) findViewById(R.id.edPassword);
        bt_Entrar = (Button) findViewById(R.id.btnEntrar);
        bt_Cadastrar = (Button) findViewById(R.id.btnCadastrar);
        btn_help = (Button) findViewById(R.id.topics_help);
        btn_exit = (Button) findViewById(R.id.topics_exit);
        
        
        // evento botao help (?)
        btn_help.setOnClickListener(new View.OnClickListener() {
                                           
                        public void onClick(View arg0) {
                                Toast.makeText(getApplicationContext(), "Feature not ready yet!!!", Toast.LENGTH_LONG).show();
                        }
                        
                });
        
        
        // evento botao exit
        btn_exit.setOnClickListener(new View.OnClickListener() {
                        
                        public void onClick(View arg0) {
                                System.exit(0);
                        }
                        
                });
        
        // evento CADASTRAR
        bt_Cadastrar.setOnClickListener(new View.OnClickListener() {
                                           
        			public void onClick(View arg0) {
        				Toast.makeText(getApplicationContext(), "Feature not ready yet!!!", Toast.LENGTH_LONG).show();
        			}
                        
                });
        
        
        
        
        // Metodo ao clicar o botao "Entrar"
        bt_Entrar.setOnClickListener(new View.OnClickListener(){
        	public void onClick(View arg0) {
        		        	
        		
        		String user = edt_User.getText().toString();
        		
        		// Se o usu�rio n�o entrar com nenhum login, envia mensagem de aviso      		        		
        		if (user.equals(""))  
        		{
        			 
        			// Mensagem de Erro
        			AlertDialog.Builder dialogo = new
                	AlertDialog.Builder(LoginActivity.this);
                	dialogo.setTitle("Aviso");
                	dialogo.setMessage("Usuário Inválido");
                	dialogo.setNeutralButton("OK", null);
                	dialogo.show();	
        			
        		}
        		else
        		{
        			
        			// Chama a outra tela!!! - > Draylson
        			Intent intent = new Intent(LoginActivity.this, CoursesActivity.class);
        			intent.putExtra("username", user);
        			intent.putExtra("novo", false);
        			LoginActivity.this.startActivity(intent);
        			System.exit(0);
        			
        			
        			
        		}
        		
        		        	
        	  }
        	       
        });
        
    }
    
    @Override
    public void onBackPressed() {
		System.exit(0);
    } 
    
}